﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Business_projectschedual : System.Web.UI.Page
{
    PM.Model.ProjectPlan PPlan = null;//项目计划实体类
    PM.PMBusiness.projectschedual BusPlan = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bind();
        }
         //读取所有框信息
        getPanelInfo();
    }

    protected void bind()
    {
        //绑定类型下拉框
        PM.Code.Web.controlbind.BindDropDownList(this.ddlType, "select btnname,id from Sys_Guide", "btnname", "id");
       
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (this.txtOpenDate.Value.Trim() == string.Empty)
        {
            PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "开启时间必须要填写！");
            return;
        }
        if (this.txtCloseDate.Value.Trim() == string.Empty)
        {
            PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "关闭时间必须要填写！");
            return;
        }
        PPlan = new PM.Model.ProjectPlan();
        BusPlan = new PM.PMBusiness.projectschedual();
        setModel(ref PPlan);
        string result= BusPlan.PlanCheck(-1,ddlType.SelectedItem.Text.Trim(),DateTime.Parse(this.txtOpenDate.Value.Trim()),DateTime.Parse(this.txtCloseDate.Value.Trim()));
        if (result.Trim() == "0002")
        {
            string plancode = BusPlan.Add(PPlan);//返回plancode
            if (plancode != string.Empty)
                Session["plancode"] = plancode.Trim();//生成session
            Response.Redirect("../Business/numbercontrol.aspx");
        }
        else
        {
            PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1,"时间和" + result + "有冲突！不能修改");
        }
    }

    protected void setModel(ref PM.Model.ProjectPlan newPPlan)
    {
        newPPlan.type = Int32.Parse(this.ddlType.SelectedValue.Trim());
        newPPlan.plevel = this.ddlPlevel.SelectedValue.Trim();
        newPPlan.ptype = this.ddlPtype.SelectedValue.Trim();
        newPPlan.opendate = DateTime.Parse( this.txtOpenDate.Value.Trim());
        newPPlan.closedate = DateTime.Parse( this.txtCloseDate.Value.Trim());
        newPPlan.builtdate = System.DateTime.Now;
        newPPlan.pstatus = "未完成";
        newPPlan.status = 0;//0为未开启
        newPPlan.operate = "毛群魁";
        newPPlan.remark = this.txtRemark.Text.ToString();
    }

    protected void getPanelInfo()
    {
        BusPlan = new PM.PMBusiness.projectschedual();
        string innerHtml=BusPlan.getProjectPlan(DateTime.Now.ToString());
        string[] array = innerHtml.Split(new char[1] { '?' });
        this.recentOpen.InnerHtml = array[0].ToString();
        this.recentClose.InnerHtml = array[1].ToString();
        this.nowRunning.InnerHtml = array[2].ToString();
    }
}
